﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using mitasoft.AdsShedule.Common;
using mitasoft.AdsShedule.Business;
using mitasoft.AdsShedule.Infrastructure;

namespace mitasoft.AdsShedule.Forms
{
    public partial class ReportV : Form
    {
        public ReportV()
        {
            InitializeComponent();
        }

        private object GetDataForReport()
        {
            var appList = BusinessAccess.Instance.DataSet.Appoiment;
            List<ReportDataClass> list = new List<ReportDataClass>();

            foreach (var day in AppCommon.GetDaysInMonth())
            {
                list.Add(CreateReportDataItem(IntervalType.AM1, day));
                list.Add(CreateReportDataItem(IntervalType.AM2, day));
                list.Add(CreateReportDataItem(IntervalType.AM3, day));
                list.Add(CreateReportDataItem(IntervalType.PM1, day));
                list.Add(CreateReportDataItem(IntervalType.PM2, day));
            }

            //foreach (var item in appList)
            //{
            //    list.Add(new ReportDataClass
            //    {
            //        Data = item.Data.ToString("dd-MMM-yyyy"),
            //        IntervalName = item.Interval,
            //        ID = item.IDVoiceAssoc > 0 ? BusinessAccess.Instance.GetVoiceClientAssociations(item.IDVoiceAssoc).Description : ""
            //    });
            //}

            return list;
        }

        private ReportDataClass CreateReportDataItem(IntervalType intervalType, DateTime date)
        {
            return new ReportDataClass
               {
                   Data = date.ToString("#dd"),
                   IntervalName = intervalType.ToString(),
                   ID = BusinessAccess.Instance.GetAppoimentInfo(date, intervalType)
               };
        }

        private void ReportV_Load(object sender, EventArgs e)
        {
            ErrorCheck.DoCheck(() =>
                {
                    this.reportViewer1.LocalReport.ReportPath = AppCommon.GetReportsPath("AppoimentReport.rdlc");
                    this.reportViewer1.LocalReport.SetParameters(new ReportParameter("Luna", AppCommon.SelectedMonth.ToString("MMMM-yyyy")));
                    this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource
                    {
                        Name = "RDC",
                        Value = GetDataForReport()
                    });
                    this.reportViewer1.RefreshReport();
                });
        }
    }
}
